﻿@using System.Diagnostics
@using System.Web
@using  Masuit.MyBlogs.Services.DTO
@using Masuit.MyBlogs.Domain.Entity
@using Masuit.Tools.Helper
@using Masuit.MyBlogs.Core.Models.ViewModel
@using Masuit.Tools.Core.Net
@using Masuit.Tools.Security
@using Masuit.Tools.Core.Configs 
@using Masuit.MyBlogs.Domain.Enum
@model  Post
@{
    ViewBag.Title = Model.Title;
    Layout = "~/Views/Shared/_Layout.cshtml";
    string[] colors = { "success", "info", "primary", "warning", "danger", "default", "primary" };
    string cid = string.IsNullOrEmpty(Context.Request.Query["cid"]) ? "0" : Context.Request.Query["cid"].ToString();
    Advertisement ad = ViewBag.Ads;
}
<environment names="Development">
    <link href="~/Assets/jquery.tocify/jquery.tocify.min.css" rel="stylesheet" />
    <link href="~/Assets/UEditor/third-party/SyntaxHighlighter/styles/shCore.min.css" rel="stylesheet" />
    <link href="~/Assets/share/share.css" rel="stylesheet" />
    <link href="~/Assets/highlight/css/highlight.css" rel="stylesheet" />
    <script src="~/Assets/share/jquery.qrcode.min.js" async defer></script>
    <script src="~/Assets/share/jquery.share.min.js" async defer></script>
    <script src="~/Assets/highlight/js/highlight.js" async defer></script>
</environment>
<environment names="Stage,Production">
    @await Styles.RenderAsync("/bundles/article.css")
    @await Scripts.RenderAsync("/bundles/article.js")
</environment>
<div class="container">
    <ol class="cd-breadcrumb triangle">
        <li><a asp-controller="Home" asp-action="Index">首页</a></li>
        <li><a asp-controller="Home" asp-action="Post">文章列表</a></li>
        <li class="current"><em>@ViewBag.Title</em></li>
    </ol>
    <div class="wrapper-content article">
        <div class="ibox">
            <div class="ibox-content animated fadeIn">
                <main>
                    <section class="article-content">
                        <header class="page-header">
                            <div class="text-center">
                                <a>
                                    <h2 class="padding-bot10">
                                        @Model.Title
                                    </h2>
                                </a>
                            </div>
                            <div class="row">
                                <div class="col-sm-8">
                                    <div class="padding-bot10">
                                        <span class="label label-@colors[new Random().Next() % colors.Length]">
                                            <a asp-controller="Home" asp-action="Author" asp-route-author="@Model.Author">@Model.Author</a>
                                        </span>发表于<span class="text-info">@Model.PostDate.ToString("yyyy-MM-dd HH:mm:ss")</span> |
                                        <span class="label label-@colors[new Random().Next() % colors.Length]">
                                            <a asp-controller="Home" asp-action="Author" asp-route-author="@Model.Modifier">@Model.Modifier</a>
                                        </span>最后修改于<span class="text-success">@Model.ModifyDate.ToString("yyyy-MM-dd HH:mm:ss")</span>
                                    </div>
                                </div>
                                @{
                                    if (!string.IsNullOrEmpty(Model.Label))
                                    {
                                        <div class="pull-right margin-right20">
                                            <div>
                                                @foreach (string s in Model.Label.Split(',', '，'))
                                                {
                                                    if (!string.IsNullOrEmpty(s))
                                                    {
                                                        <a asp-controller="Home" asp-action="Tag" asp-route-id="@s">
                                                            <span class="label label-@colors[new Random().Next() % colors.Length]">@s</span>
                                                        </a>
                                                    }
                                                }
                                            </div>
                                        </div>
                                    }
                                }
                            </div>
                            <div class="row">
                                <div class="col-md-12 line-height24">
                                    分类：<i class="icon-map-pin"></i><a asp-controller="Home" asp-action="Category" asp-route-id="@Model.CategoryId" class="label label-@colors[new Random().Next() % colors.Length]">@Model.Category.Name</a> | 评论总数：<span class="text-danger">@Model.Comment.Count</span>条 | 热度：<span class="text-danger">@Model.TotalViewCount</span>℃
                                    @if (Model.Seminar.Any())
                                    {
                                        <span> | 所属专题：</span>
                                        var seminars = Model.Seminar;
                                        foreach (var s in seminars)
                                        {
                                            <a asp-controller="Seminar" asp-action="Index" asp-route-id="@s.SeminarId" class="label label-@colors[new Random().Next() % colors.Length]">@s.Seminar.Title</a>
                                            <text> </text>
                                        }
                                    }
                                    <div class="pull-right margin-right20">
                                        <a asp-controller="Post" asp-action="PushMerge" asp-route-id="@Model.Id" class="btn btn-danger">我要编辑</a>
                                    </div>
                                </div>
                            </div>
                        </header>
                        <article class="article" id="article">
                            @Html.Raw(Model.Content.ReplaceImgAttribute(Model.Title))
                            @if (!string.IsNullOrEmpty(Model.ProtectContent))
                            {
                                <div class="row protected">
                                    @if (!string.IsNullOrEmpty(Context.Session.Get<string>("AccessViewToken")) || Context.Request.Cookies["Email"].MDString3(AppConfig.BaiduAK).Equals(Context.Request.Cookies["PostAccessToken"]))
                                    {
                                        <p class="text-red text-center size20">↓↓↓以下是文章加密部分↓↓↓</p>
                                        @Html.Raw(Model.ProtectContent.ReplaceImgAttribute(Model.Title))

                                    }
                                    else
                                    {
                                        <p class="text-red text-center size24 margin-bot10">↓↓↓恭喜你发现镇站之宝，请注意，前方高能！非战斗人员请及时撤离，这不是演习！↓↓↓</p>
                                        <div class="col-md-12">
                                            <span class="text-red">以下内容已经隐藏，请输入验证码后查看</span>
                                            <span class="text-green">【完全免费，不收一分钱】</span>
                                            <form action="/" method="post" class="form-inline" id="code-token">
                                                @Html.AntiForgeryToken()
                                                <div class="input-group">
                                                    <span class="input-group-addon">邮箱：</span>
                                                    <input type="email" name="Email" id="email3" class="form-control" />
                                                    <span class="input-group-btn">
                                                        <button type="button" class="btn btn-info getcode">获取验证码</button>
                                                    </span>
                                                </div>
                                                <div class="input-group">
                                                    <span class="input-group-addon">验证码：</span>
                                                    <input type="text" name="token" id="token" class="form-control" />
                                                    <span class="input-group-btn">
                                                        <button type="submit" class="btn btn-info">查看文章</button>
                                                    </span>
                                                </div>
                                            </form>
                                            <p class="text-green">温馨提示：<span class="text-red">获取密码后本站所有加密文章将永久开放！请确保您的邮箱已经通过站长的登记，如果您未使用邮箱登记，请先联系站长获取文章密码并登记邮箱即可！</span></p>
                                        </div>
                                    }
                                </div>
                            }
                        </article>
                        <h3>分享到：</h3>
                        <div class="social-share"></div>
                        <div id="cyReward" role="cylabs" data-use="reward"></div>
                    </section>
                </main>
                @if (ad != null)
                {
                    <section class="protected">
                        <a asp-controller="Advertisement" asp-action="Redirect" asp-route-id="@ad.Id" target="_blank" id="@Stopwatch.GetTimestamp()">
                            <h3>
                                @ad.Title
                                <span class="text-red">[推广]</span>
                            </h3>

                            <div class="row padding-bot10">
                                @{
                                    string imgSrc = ad.ThumbImgUrl;
                                    if (!string.IsNullOrEmpty(imgSrc))
                                    {
                                        <div class="col-md-3">
                                            <img class="img-thumbnail img-responsive thumb" data-original="@imgSrc" alt="@ad.Title" title="@ad.Title ">
                                        </div>
                                    }
                                }
                                <div class="col-md-@(string.IsNullOrEmpty(imgSrc) ? 12 : 9)">
                                    <p>
                                        @ad.Description
                                    </p>
                                </div>
                            </div>
                        </a>
                    </section>
                }
                <section class="wow row padding-top40 padding-bot20 animated fadeIn">
                    <div class="col-xs-6">
                        <div class="btn-group">
                            <button type="button" id="voteup" class="btn btn-success btn-lg">
                                <i class="icon-thumbsup"></i><span>@Model.VoteUpCount</span>
                            </button>
                            <button type="button" id="votedown" class="btn btn-danger btn-lg">
                                <i class="icon-thumbsdown"></i><span>@Model.VoteDownCount</span>
                            </button>
                        </div>
                    </div>
                    <div class="col-xs-6 text-right">
                        <div class="btn-group">
                            <a class="btn btn-danger btn-lg" asp-controller="Subscribe" asp-action="PostRss" asp-route-id="@Model.Id" target="_blank">
                                <i class="icon-rss4"></i><span>订阅本文更新</span>
                            </a>
                            <button type="button" id="donate" class="btn btn-info btn-lg">
                                <i class="icon-coin-yen"></i><span>支持站长</span>
                            </button>
                        </div>
                    </div>
                </section>
                <section class="wow fadeInUp row size16">
                    <div class="col-xs-6">
                        上一篇：
                        @{
                            PostModelBase prev = ViewBag.Prev;
                            if (prev != null)
                            {
                                <a asp-controller="Post" asp-action="Details" asp-route-id="@prev.Id">@prev.Title</a>
                            }
                            else
                            {
                                <a>没有了</a>
                            }
                        }
                    </div>
                    <div class="col-xs-6 text-right">
                        下一篇：
                        @{
                            PostModelBase next = ViewBag.Next;
                            if (next != null)
                            {
                                <a asp-controller="Post" asp-action="Details" asp-route-id="@next.Id">@next.Title</a>
                            }
                            else
                            {
                                <a>没有了</a>
                            }
                        }
                    </div>
                </section>
                <section class="wow padding-bot20 animated fadeIn">
                    <h3>版权声明：</h3>
                    <p class="text-red size16">
                        @if (Model.DisableCopy)
                        {
                            <text>🈲⚠本文为作者原创，仅用于本站访客学习、研究和交流目的，未经授权禁止转载。️⚠🈲 </text>
                        }
                        else
                        {
                            <text>本文仅用于学习、研究和交流目的，欢迎非商业性质转载。本文链接：<a asp-controller="Post" asp-action="Details" asp-route-id="@Model.Id">@HttpUtility.UrlDecode(Context.Request.Scheme + "://" + Context.Request.Host + Context.Request.Path)</a>。</text>
                            @Html.Raw(CommonHelper.SystemSettings["Disclaimer"])
                        }
                    </p>
                </section>
                @if (Model.PostHistoryVersion.Any())
                {
                    <section class="wow margintop20 animated fadeIn">
                        <h3>文章历史版本：</h3>
                        <p>
                            修改次数：@Model.PostHistoryVersion.Count 次
                            <a asp-controller="Post" asp-action="History" asp-route-id="@Model.Id">查看历史版本</a>
                        </p>
                    </section>
                }
                @{
                    var posts = Model.Category.Post.Where(p => p.Status == Status.Published && p.Id != Model.Id).OrderBy(p => Guid.NewGuid()).ToList();
                    int count = posts.Count >= 10 ? 10 : posts.Count;
                    if (posts.Any())
                    {
                        <section class="wow margintop20 animated fadeIn">
                            <h3>相关推荐：</h3>
                            <table class="table table-condensed size16">
                                @for (int i = 1; i < count; i += 2)
                                {
                                    <tr>
                                        <td style="width: 50%"><a asp-controller="Post" asp-action="Details" asp-route-id="@posts[i - 1].Id">@posts[i - 1].Title</a></td>
                                        <td><a asp-controller="Post" asp-action="Details" asp-route-id="@posts[i].Id">@posts[i].Title</a></td>
                                    </tr>
                                }
                            </table>
                        </section>
                    }
                }
                <hr>
                <section class="wow row animated fadeIn">
                    <div class="col-lg-12">
                        <h3>评论区：</h3>
                        @if (!Model.DisableComment)
                        {
                            <form class="form-horizontal animated pulse" id="comment" method="post">
                                @Html.AntiForgeryToken()
                                <input type="hidden" name="PostId" value="@Model.Id" />
                                <input type="hidden" id="OperatingSystem" name="OperatingSystem" />
                                <input type="hidden" name="Browser" id="Browser" />
                                <div class="row">
                                    <div class="col-md-4">
                                        <div class="input-group">
                                            <span class="input-group-addon">
                                                <label for="name">昵称：</label>
                                            </span>
                                            <input type="text" class="form-control" name="NickName" id="name" required placeholder="昵称">
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="input-group">
                                            <span class="input-group-addon">
                                                <label for="email">邮箱：</label>
                                            </span>
                                            <input type="email" class="form-control" name="Email" id="email" required placeholder="留下您的真实邮箱，以方便接收回复">
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="input-group">
                                            <span class="input-group-addon">
                                                <label for="chat">QQ/微信：</label>
                                            </span>
                                            <input type="text" class="form-control" name="QQorWechat" id="chat" placeholder="QQ或微信(可选)">
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group overlay animated fadeInDown" style="margin-bottom: 0px !important;">
                                    <textarea class="layui-textarea" id="layedit" name="Content" style="height: 100px"></textarea>
                                </div>
                                <input type="checkbox" name="Agree" id="aggrement" value="true" /><label for="aggrement">我已接受<a asp-controller="Misc" asp-action="agreement" target="_blank">《评论须知》</a></label>
                                <div class="form-group">
                                    <div class="col-xs-6">
                                        <button type="submit" class="btn btn-info btn-lg">提交</button>
                                        <a class="text-red">评论框可粘贴网络图片</a>
                                    </div>
                                    <div class="col-xs-6 text-right">
                                        <a class="btn btn-danger btn-lg" asp-controller="Subscribe" asp-action="CommentsRss" asp-route-id="@Model.Id" target="_blank">
                                            <i class="icon-rss4"></i><span>订阅本文评论更新</span>
                                        </a>
                                    </div>
                                </div>
                            </form>
                        }
                        else
                        {
                            <h4>本篇文章已禁用评论和回复功能</h4>
                        }
                        <ul class="wow media-list"></ul>
                        @if (Model.Comment.Any(c => c.Status == Status.Published))
                        {
                            <div class="row">
                                <div class="col-md-12 text-center">
                                    <div id="pageToolbar"></div>
                                </div>
                            </div>
                        }
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>
<div style="position: absolute; left: -20000px; bottom: 0;">
    <div id="reply" class="container-fluid">
        <form class="form-horizontal" id="reply-form" method="post">
            @Html.AntiForgeryToken()
            <input type="hidden" name="PostId" id="postId" value="@Model.Id" />
            <input type="hidden" name="OperatingSystem" id="OperatingSystem2" />
            <input type="hidden" name="Browser" id="Browser2" />
            <div class="input-group">
                <span class="input-group-addon">
                    <label for="name">昵称：</label>
                </span>
                <input type="text" class="form-control" name="NickName" id="name2" required placeholder="昵称">
            </div>
            <div class="input-group">
                <span class="input-group-addon">
                    <label for="email">邮箱：</label>
                </span>
                <input type="email" class="form-control" name="Email" id="email2" required placeholder="留下您的真实邮箱，以方便接收回复">
            </div>
            <div class="input-group">
                <span class="input-group-addon">
                    <label for="chat">QQ/微信：</label>
                </span>
                <input type="text" class="form-control" name="QQorWechat" id="chat2" placeholder="QQ或微信(可选)">
            </div>
            <input type="hidden" value="" id="uid" name="ParentId" />
            <div class="form-group overlay animated fadeInDown">
                <textarea class="layui-textarea" id="layedit2" name="Content" style="height: 80px"></textarea>
            </div>
            <input type="checkbox" name="Agree" id="aggrement2" value="true" /><label for="aggrement2">我已接受<a asp-controller="Misc" asp-action="agreement" target="_blank">《评论须知》</a></label>
            <div class="form-group">
                <div class="col-xs-12">
                    <div class="btn-group">
                        <button type="submit" class="btn btn-info btn-lg">
                            提交回复
                        </button>
                        <button type="button" class="btn-cancel btn btn-danger btn-lg">
                            取消回复
                        </button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<noscript>
    <iframe src="*.htm"></iframe>
</noscript>
<script>
    @if(Model.DisableCopy) {
        <text>
    GlobalCopyrightProtect();
        </text>
    }
    window.onload = function() {
        var keywords = @Html.Raw(ViewData["keywords"] ?? "[]");
        for (var i = 0; i < keywords.length; i++) {
            $("#article").highlight(keywords[i]);
        }
        loading();
        $('#pageToolbar').Paging({ //异步加载评论
            pagesize: 10,
            count: @Model.Comment.Count(c =>c.ParentId==0&& c.Status==Status.Published),
            toolbar: true,
            callback: function(page, size, count) {
                window.post("/comment/getcomments", {
                    id: @Model.Id,
                    page: page,
                    size: size
                }, function(data) {
                    data = data.Data;
                    if (data) {
                        document.querySelector(".media-list").innerHTML = loadParentComments(data);
                        bindReplyBtn();
                        commentVoteBind(); //评论投票
                    }
                });
            }
        });
        loadingDone();
    };

    /**
   * 获取评论
   */
    function getcomments() {
        window.post("/comment/getcomments", {
            id: $("#postId").val(),
            page: 1,
            size: 10,
            cid:@cid
        }, function(data) {
            data = data.Data;
            if (data) {
                document.querySelector(".media-list").innerHTML = loadParentComments(data);
                bindReplyBtn();
                commentVoteBind(); //评论投票
            }
        });
    }
</script>